package Demo1299.Demo19;

public class Dmeo1 {
    public static void main(String[] args) throws Exception {
        Object[] objects = {"大黄蜂"};
        Object newInstance = new Dmeo1().newInstance("Demo1299.Demo5.Cat", objects);
        System.out.println(newInstance);
    }

    public Object newInstance(String className, Object[] args) throws Exception{
        Class<?> aClass = Class.forName(className);
        Object cat = aClass.getDeclaredConstructor().newInstance();
        for (Object arg : args) {
            String str = (String) arg;
            aClass.getDeclaredMethod("setName", String.class).invoke(cat, str);
        }
        return cat;
    }
}
